package com.bgs.service.impl;

import com.alibaba.excel.EasyExcel;
import com.bgs.dao.UMapper;
import com.bgs.dao.UserteMapper;
import com.bgs.dao.studentInformationMapper;
import com.bgs.listener.StuExcelListener;
import com.bgs.listener.UserExcelListener;
import com.bgs.pojo.*;
import com.bgs.pojo.data.stuInfoData;
import com.bgs.pojo.data.stuInfoDatss;
import com.bgs.pojo.vo.uVO;
import com.bgs.service.StudenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@Service
public class StudenServiceImpl implements StudenService {

    @Autowired
    private studentInformationMapper s;
    @Autowired
    private UMapper uu;
    @Autowired
    private UserteMapper userteMapper;

    //全查
    @Override
    public List<studentInformation> findAllqc() {

        List<studentInformation> stu = s.findAllqc();

        return stu;
    }


    //模糊查
    @Override
    public List<studentInformation> findAll(studentInformation studentInformation) {

        List<studentInformation> stu = s.findAll(studentInformation);

        return stu;
    }

    //添加
    @Override
    public int insertSelective(studentInformation studentInformation) {
        return s.insertSelective(studentInformation);
    }

    //省下拉框
    @Override
    public List<Provinces> provinces() {
        return s.provinces();
    }
    //市下拉框
    @Override
    public List<Cities> cities() {
        return s.cities();
    }
    //县下拉框
    @Override
    public List<Areas> areas() {
        return s.areas();
    }

    @Override
    public int updateByPrimaryKeySelective(studentInformation studentInformation) {
        return s.updateByPrimaryKeySelective(studentInformation);
    }

    @Override
    public int deleteById(Integer id) {
        return s.deleteByPrimaryKey(id);
    }

    @Override
    public List<studentInformation> stuexport(studentInformation sVO) {
        return s.stuexport(sVO);
    }

    @Override
    public void inse(List<studentInformation> readResult) {
        s.inse(readResult);
    }

    @Override
    public studentInformation selectByPrimaryKey(Integer id) {
        return s.selectByPrimaryKey(id);
    }

    @Override
    public List<U> finduAll(uVO u) {
        return uu.findu(u);
    }

    @Override
    public List<stuInfoData> select() {
        return s.select();
    }

    @Override
    public void addStuExel(MultipartFile file, StudenService studenService) {
        try {
            //先获取文件输入流
            InputStream in = file.getInputStream();
//             这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
//            EasyExcel.read(fileName, stuInfoDatss.class, new StuExcelListener(studenService)).sheet().doRead();
            EasyExcel.read(in, stuInfoDatss.class, new StuExcelListener(studenService)).sheet().doRead();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @Override
    public int insertStuExcel(studentInformation studentInformation) {
        System.out.println("正在添加！！！");
        return s.insertStuExcel(studentInformation);
    }

    @Override
    public List<Userte> selectuu() {
        return userteMapper.selectuu();
    }

    @Override
    public void addUser(String fileName, StudenService studenService) {
        EasyExcel.read(fileName, Userte.class, new UserExcelListener(studenService)).sheet().doRead();
    }

    @Override
    public int addUserExcel(Userte u) {
        return userteMapper.insertSelective(u);
    }


}
